package com.by.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.by.entity.Brand;
import com.by.service.BrandService;
import com.by.mapper.BrandMapper;
import com.by.vo.BrandVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author 16564
* @description 针对表【pms_brand(商品品牌)】的数据库操作Service实现
* @createDate 2025-10-11 09:44:17
*/
@Service
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand>
    implements BrandService {
    @Override
    public IPage<BrandVo> pageBrand(int pageNum, int pageSize, String name) {
        Page<Brand> page = new Page<>(pageNum, pageSize);

        // 查询分页数据
        // 构造查询条件，增加非空判断
        QueryWrapper<Brand> queryWrapper = new QueryWrapper<>();
        if (name != null && !name.trim().isEmpty()) {
            queryWrapper.like("name", name.trim()); // trim() 避免前端传空格导致的无效查询
        }

        // 执行查询
        IPage<Brand> brandPage = baseMapper.selectPage(page, queryWrapper);

        // 转换为 BrandVo
        return brandPage.convert(brand -> {
            BrandVo vo = new BrandVo();
            vo.setBrandId(brand.getBrandId());
            vo.setName(brand.getName());
            vo.setLogo(brand.getLogo());
            vo.setDescript(brand.getDescript());
            vo.setHomepageUrl(brand.getHomepageUrl());
            vo.setShowStatus(brand.getShowStatus());
            return vo;
        });
    }


}



